/* eslint-disable react-hooks/rules-of-hooks */
import { Button, NavBar } from 'antd-mobile'
import React from 'react'
import { useNavigate, useSearchParams } from 'react-router-dom'
import styles from './css/list.module.css'
import TrainList from './computents/TrainList'
import { getTrainListApi } from '../../api/train'
function index() {
  
    let nav=useNavigate()
    const [sp]=useSearchParams()
  return (
    <div className={styles.box}>
      <NavBar className={styles.Nav} onBack={()=>nav(-1)}>{sp.get('start')+'→'+sp.get('end')}</NavBar>
       
      <TrainList/>
    </div>
  )
}

export default index

export const loader=async({request})=>{

    const url=new URL(request.url)
    const obj=Object.fromEntries(url.searchParams)
    const {data:list}=await getTrainListApi(obj)
    // console.log(list);
    
    return{list}
}